package StubDriver;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.UnhandledAlertException;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class FirstStub extends Driver {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public void FirefoxBrowser() throws UnhandledAlertException, IOException  {
		// TODO Auto-generated method stub
    
	Browser=new FirefoxDriver();
	Browser.get(URL);
	Browser.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
	Browser.manage().window().maximize();
	Browser.findElement(By.xpath("html/body/form/div/table[3]/tbody/tr/td/table/tbody/tr[4]/td/input[1]")).click();
	//Browser.findElement(By.cssSelector("input.radioTermsCond[value=Y]")).click();
	Browser.findElement(By.className("button")).click();
	try{
	WebDriverWait wait = new WebDriverWait(Browser, 3);
	wait.until(ExpectedConditions.alertIsPresent());
    //Alert alert = Browser.switchTo().alert();
    //alert.accept();
    File scrFile = ((TakesScreenshot)Browser).getScreenshotAs(OutputType.FILE);
	// Now you can do whatever you need to do with it, for example copy somewhere
	FileUtils.copyFile(scrFile, new File("/home/qateam/Desktop/Error.png"));
	System.out.println("Captured Successfully");
    Browser.quit();
	}
		
	catch(Exception E){
		 File scrFile = ((TakesScreenshot)Browser).getScreenshotAs(OutputType.FILE);
		 FileUtils.copyFile(scrFile, new File("/opt/Error.png"));
		 System.out.println("Screenshot Captured Successfully");
		 Browser.quit();
		}
	}
	

}
